package com.example.idachuappone.index.dao.impl;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.example.idachuappone.index.dao.WelcomeDao;
import com.example.idachuappone.index.welcomentity.InitData;
import com.example.idachuappone.promptly.dao.DBHelper;

public class WelcomeDaoImpl implements WelcomeDao {
    private Context context;
    DBHelper db;
    private SQLiteDatabase rd;
    private SQLiteDatabase wd;

    public WelcomeDaoImpl(Context context) {
        this.context = context;
        this.db = new DBHelper(context);
    }

    public InitData selectByName(String name) {
        this.rd = this.db.getReadableDatabase();
        Cursor cursor = this.rd.rawQuery("select * from initdata where activityname=?", new String[]{new StringBuilder(String.valueOf(name)).toString()});
        InitData initData = null;
        if (cursor.moveToNext()) {
            initData = new InitData(cursor.getString(0), cursor.getString(1));
        }
        cursor.close();
        this.rd.close();
        return initData;
    }

    public void add(InitData initData) {
        this.wd = this.db.getWritableDatabase();
        this.wd.execSQL("insert into initdata(activityname,init) values(?,?)", new String[]{initData.getActivityname(), initData.getInit()});
        this.wd.close();
    }

    public void update(InitData initData) {
        this.wd = this.db.getWritableDatabase();
        this.wd.execSQL("update initdata set init=? where activityname=?", new String[]{initData.getInit(), initData.getActivityname()});
        this.wd.close();
    }
}
